#include <set>
using namespace std;

class Solution {
public:
  int singleNumber(int A[], int n) {
    
    set<int> mySet;
    for(int i = 0; i < n; i++)
    {
        if(mySet.find(A[i]) != mySet.end())
        {   
        //if the integer is in the set, erase it.
            mySet.erase(A[i]);
            //cout << "Found " << A[i] << " in mySet. Erased it." << endl;
        }   
        else
        {   
        //else, insert this integer to the set.
            mySet.insert(A[i]);
        }   
    }

    int singleNumber = *mySet.begin();

    return singleNumber;
    }
};
